package com.fise.localvideo.firstdemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.fise.localvideo.R;

import java.util.List;

public class LocalVideoItemAdapter extends ArrayAdapter<LocalVideoInfo> {

    private final LayoutInflater mInflater;
    private final int mResource;

    public LocalVideoItemAdapter(@NonNull Context context, int resource, @NonNull List<LocalVideoInfo> objects) {
        super(context, resource, objects);
        this.mInflater = LayoutInflater.from(context);
        this.mResource = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(mResource, parent, false);
        }

        LocalVideoInfo item = getItem(position);


        TextView title = (TextView) convertView.findViewById(R.id.video_title);
        //title.setText(item.getName());
        title.setText(item.getDisplayName());
        TextView createTime = (TextView) convertView.findViewById(R.id.video_date);
        //createTime.setText((CharSequence) item.getCreatedTime());
        createTime.setText((CharSequence) item.getDisplayDuration());
        ImageView thumb = (ImageView) convertView.findViewById(R.id.vidoe_thumb);
        thumb.setImageBitmap(item.getThumb());

        return convertView;
    }
}
